package jdbc;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

public class RegDemo2 {
    public static void main(String[] args) {
        UserInfo userInfo =InputUtil.getInputObject(new UserInfo());
        System.out.println(userInfo);
        int num= reg(userInfo);
    }

    public static int reg(UserInfo userInfo) {
        try(Connection connection=DBUtil.getConnection();) {
            Statement statement=connection.createStatement();
            String sql;
            sql="INSERT INTO userinfo(username, password, nickname, age) " +
                    "VALUES ('" + userInfo.getUsername() + "','" + userInfo.getPassword() + "','" + userInfo.getNickname() + "','" + userInfo.getAge() + "')";
            System.out.println(sql);
            int num=statement.executeUpdate(sql);
            return num;
        } catch (SQLException e) {
           e.printStackTrace();
        }

        return 0;

    }
}
